package com.homson.coreservice.serviceapp.account;

import com.homson.coreservice.serviceapi.action.AccountActionApi;
import com.homson.coreservice.servicecommon.co.AccountCreateCO;
import com.homson.coreservice.servicecommon.request.AccountCreateRequest;
import com.homson.coreservice.servicecommon.request.RequestParameter;
import com.homson.coreservice.servicecommon.response.BaseResponse;
import com.homson.servicedomain.domain.account.AccountCreateCommand;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/8 3:26 PM
 **/
@Service
@Slf4j
public class AccountActionService implements AccountActionApi {
    
    @Resource
    private AccountCreateCommand accountCreateCommand;
    
    @Override
    public BaseResponse createAccount(RequestParameter<AccountCreateRequest> request) {
        // valiadate service TODO 输入不为空
        Long userId = request.getBody().getUserId();
        AccountCreateCO accountCreateCO = request.getBody().getAccountCreateCO();
        try {
            accountCreateCommand.createAccount(userId, accountCreateCO);
            return BaseResponse.ok();
        } catch (Exception e) {
            log.error(AccountActionService.class.getSimpleName(), e);
            return BaseResponse.fail(e.getMessage());
        }
    }
}
